package com.zsy.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zsy.service.BBSService;

public class AddSite extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession sess = req.getSession();
		try {
			req.setCharacterEncoding("UTF-8");
			String site_ch = req.getParameter("site_ch");
			String site_en = req.getParameter("site_en");
			String page = req.getParameter("page");
			if(null == page||(null!=page&&Integer.parseInt(page)<=0)){
				page="1";
			}
			BBSService bbss = new BBSService();
			bbss.saveSite(site_ch, site_en);
			sess.setAttribute("msg", "网站添加成功!");
			resp.sendRedirect("allSites");
		}catch(Exception e){
			sess.setAttribute("msg", "网站添加重复，请重新添加!");
			resp.sendRedirect("allSites");
		}
	}
}
